﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DrugStorehouseMIS.DAL;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;


namespace DrugStorehouseMIS.BLL
{
    public class StockOutType
    {
         #region 封装属性

        private int mStockOutTypeNum;

        public int StockOutTypeNum
        {
            get { return mStockOutTypeNum; }
            set { mStockOutTypeNum = value; }
        }

        private string mStockOutTypeName;

        public string StockOutTypeName
        {
            get { return mStockOutTypeName; }
            set { mStockOutTypeName = value; }
        }

        private string mStockOutTypeCode;

        public string StockOutTypeCode
        {
            get { return mStockOutTypeCode; }
            set { mStockOutTypeCode = value; }
        }

        #endregion

        private IStockOutTypeDAL StockOutTypeDAL;

        public StockOutType()
        {
            StockOutTypeDAL = Adapter.GetStockOutType();
        }

        /// <summary>
        /// 获取整个对象
        /// </summary>
        /// <param name="dr"></param>
        public void FetchObject(IDataReader dr)
        {
            if (dr!=null)
            {
                mStockOutTypeNum = ConvertDataType.CheckFiledInt(dr["stock_out_type_num"]);
                mStockOutTypeName = ConvertDataType.CheckFiledString(dr["stock_out_type_name"]);
                mStockOutTypeCode = ConvertDataType.CheckFiledString(dr["stock_out_type_code"]);
            }
        }

        /// <summary>
        ///  创建对象
        /// </summary>
        /// <param name="stockOutType"></param>
        /// <returns></returns>
        public StockOutType GetStockInType(string name)
        {
            StockOutType obj = new StockOutType();
            IDataReader dr = StockOutTypeDAL.Select(name);
            while (dr != null && dr.Read())
            {
                obj.FetchObject(dr);
            }
            return obj;
        }
        public DataTable Display()
        {
            return StockOutTypeDAL.SelectAll();
        }
        public bool CreateStockOutType(StockOutType stockOutType)
        {
            return StockOutTypeDAL.Insert(stockOutType.mStockOutTypeName, stockOutType.mStockOutTypeCode) > 0 ? true : false;
        }

        /// <summary>
        /// 更新对象
        /// </summary>
        /// <param name="stockOutType"></param>
        /// <returns></returns>
        public bool SetStockOutType(StockOutType stockOutType)
        {
            return StockOutTypeDAL.Update(stockOutType.mStockOutTypeNum, stockOutType.mStockOutTypeName, stockOutType.mStockOutTypeCode) > 0 ? true : false;
        }

        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="stockOutTypeNum"></param>
        /// <returns></returns>
        public bool RemoveStockOutType(int stockOutTypeNum)
        {
            return StockOutTypeDAL.Delete(stockOutTypeNum) > 0 ? true : false;
        }

        /// <summary>
        /// 获取已有的全部对象
        /// </summary>
        /// <returns></returns>
        public IList<StockOutType> GetAllStockOutType()
        {
            IList<StockOutType> list = new List<StockOutType>();
            IDataReader dr = StockOutTypeDAL.Select();
            while (dr != null && dr.Read())
            {
                StockOutType stockOutType = new StockOutType();
                stockOutType.FetchObject(dr);
                list.Add(stockOutType);
            }
            if (dr != null) dr.Close();
            return list;
        }

        /// <summary>
        /// 根据名称获取对象
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public StockOutType GetStockOutType(string name)
        {
            StockOutType obj = new StockOutType();
            IDataReader dr = StockOutTypeDAL.Select(name);
            while (dr != null && dr.Read())
            {
                obj.FetchObject(dr);
            }
            return obj;
        }
    }
}
